//
//  LZEmailRegisterView.m
//  laziz_Merchant
//
//  Created by xbnzd on 17/3/16.
//  Copyright © 2017年 XBN. All rights reserved.
//

#import "LZEmailRegisterView.h"

@interface LZEmailRegisterView()
@property (weak, nonatomic) IBOutlet UIButton *showOrHiddenPasswordBtn;
@property (weak, nonatomic) IBOutlet UILabel *agreementLabel;
@property (weak, nonatomic) IBOutlet UIButton *agreementBtn;

@end

@implementation LZEmailRegisterView

- (void)awakeFromNib
{
    [super awakeFromNib];
    
    [self configureUI];
}

- (void)goReadAgreement
{
    if (self.clickAgreementLabelBlock) {
        self.clickAgreementLabelBlock();
    }
}
#pragma mark - UI
- (void)configureUI
{
    self.isAgreement = YES;
    self.agreementBtn.selected = YES;
    
    GET_SCREEN_SCALE(scale);
    
    self.emailTF.font = [UIFont systemFontOfSize:17*scale];
    self.emailTF.placeholder = LZLocalizedString(@"login_email", nil);
    [self.emailTF setTintColor:UIColorFromRGB(0x33a928, 1)];
    [self.emailTF setValue:UIColorFromRGB(0x999999, 1) forKeyPath:@"_placeholderLabel.textColor"];
    
    self.passwordTF.font = [UIFont systemFontOfSize:17*scale];
    self.passwordTF.placeholder = LZLocalizedString(@"password_text", nil);
    self.passwordTF.secureTextEntry  = YES;
    [self.passwordTF setTintColor:UIColorFromRGB(0x33a928, 1)];
    [self.passwordTF setValue:UIColorFromRGB(0x999999, 1) forKeyPath:@"_placeholderLabel.textColor"];
    
    NSString *strStart = LZLocalizedString(@"register_termsofservice", @"");
    NSString *strEnd = LZLocalizedString(@"terms_of_service", nil);
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ \" %@ \"",strStart,strEnd]];
    [attStr addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0x999999, 1) range:NSMakeRange(0, strStart.length)];
    [attStr addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0x33a928, 1) range:NSMakeRange(strStart.length, strEnd.length + 5)];
    self.agreementLabel.attributedText = attStr;
    
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(goReadAgreement)];
    self.agreementLabel.userInteractionEnabled = YES;
    [self.agreementLabel addGestureRecognizer:tap2];
}

#pragma mark - btn action
- (IBAction)agreementBtnAction:(id)sender {

    self.agreementBtn.selected = !self.agreementBtn.isSelected;
    if (self.agreementBtn.isSelected) {
        self.isAgreement = YES;
    }else{
        self.isAgreement = NO;
    }

}

- (IBAction)showOrHiddenPasswordBtnAction:(id)sender {
    self.showOrHiddenPasswordBtn.selected = !self.showOrHiddenPasswordBtn.isSelected;
    if (self.showOrHiddenPasswordBtn.isSelected) {
        self.passwordTF.secureTextEntry = NO;
    }else{
        self.passwordTF.secureTextEntry = YES;
    }
}

@end
